<%--
  Created by IntelliJ IDEA.
  User: Rui
  Date: 2018/9/8
  Time: 9:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../resources/inc/head.jsp" %>
</head>
<body>
<expect-x:tip tipMessage="标识“*”的选项为必填项，其余为选填项。;请按提示信息填写每一个字段" widthClass="full-width-85"/>

<div class="layui-form common-form" lay-filter="layuiadmin-form-paymentChannel" id="layuiadmin-form-paymentChannel" style="padding: 20px;">

    <div class="layui-form-item">
        <input type="hidden" value="${paymentChannel.id}" name="id">
        <label class="layui-form-label"><span class="require-field">*</span>渠道名称</label>
        <div class="layui-input-inline">
            <input type="text" value="${paymentChannel.name}" maxlength="45"name="name" lay-verify="required" placeholder="请输入渠道名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="require-field">*</span>渠道属性</label>
        <div class="layui-input-inline">
            <input type="text" value="${paymentChannel.channelAttr}" maxlength="45" name="channelAttr" lay-verify="required" placeholder="请输入渠道属性" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="require-field">*</span>费率</label>
        <div class="layui-input-inline">
            <input type="text" value="${paymentChannel.rate}"maxlength="45"   name="rate" lay-verify="required" placeholder="请输入费率" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">%</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="require-field">*</span>原始费率</label>
        <div class="layui-input-inline">
            <input type="text" value="${paymentChannel.payRate}"maxlength="45" name="payRate" lay-verify="required" placeholder="请输入原始费率" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">%</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="require-field">*</span>结算周期</label>
        <div class="layui-input-inline">
            <select name="settlementCycle" lay-verify="required" placeholder="请选择" autocomplete="off">
                <option value="${paymentChannel.settlementCycle}" >${paymentChannel.settlementCycle==null?"请选择":paymentChannel.settlementCycle}</option>
                <option value="D+0" >D+0</option>
                <option value="D+1">D+1</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="require-field">*</span>结算周期</label>
        <div class="layui-input-inline">
            <select name="type" lay-verify="required" placeholder="请选择" autocomplete="off">
                <option value="${paymentChannel.type}" >${paymentChannel.type==null?"请选择":paymentChannel.type==1?"支付宝":paymentChannel.type==2?"微信":"银联"}</option>
                <option value="1" >支付宝</option>
                <option value="2">微信</option>
                <option value="3" >银联</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="require-field">*</span>使用场景</label>
        <div class="layui-input-inline">
            <textarea name="useCase" placeholder="请输入使用场景" class="layui-textarea" rows="6" cols="85" maxlength="500">${paymentChannel.useCase}</textarea>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
    </div>
</div>

<%@include file="../../../resources/inc/footer.jsp" %>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,upload = layui.upload ;
    })
    function createSubmit() {
        var layer=layui.layer;
        var submitID = 'LAY-submit';
        layui.form.on('submit('+ submitID +')', function(data){
            var formData = data.field;
            /*费率及原始费率判断*/
            if (formData.rate>=100) {
                return layer.msg('费率不能超过100');
            }
            if (formData.payRate>=100) {
                return layer.msg('原始费率不能超过100');
            }
            if (formData.payRate>formData.rate) {
                return layer.msg('原始费率不能大于费率');
            }

            layer.load(2);
            console.log(formData);


            if(formData.id==""||formData.id==null){
                formData.id = null;
            $.ajax({
                url:"<%=basePath%>manager/system/paymentChannel/create.html",
                type:"POST",
                data:formData,
                dataType:"JSON",
                success:function (data) {
                    layer.closeAll('loading');
                    if(data.success){
                        layer.msg("创建成功,1秒后跳转")
                        setTimeout(function () {
                            window.parent.location.reload(); //刷新父页面
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);
                        },1000);
                    }else{
                        layer.msg(data.message, {icon: 5});
                    }
                }
            });
            }else{
                $.ajax({
                    url:"<%=basePath%>manager/system/paymentChannel/update/"+formData.id+".html",
                    type:"POST",
                    data:formData,
                    dataType:"JSON",
                    success:function (data) {
                        layer.closeAll('loading');
                        if(data.success){
                            layer.msg("修改成功,1秒后跳转")
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);
                            },1000);
                        }else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
        })
        $("#"+submitID).trigger('click');
    }
</script>
</body>
</html>
